package com.zhilehuo.controller;

import com.github.houbb.pinyin.util.PinyinHelper;
import com.zhilehuo.common.BaseResponse;
import com.zhilehuo.model.request.ChangeWordRequest;
import com.zhilehuo.service.IWordService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/pronunciation")
@CrossOrigin(origins = "*")
public class WordController {

    @Resource
    private IWordService wordService;

    //获取当前汉字的所有拼音列表
    @RequestMapping(value = "/pinyin", method = RequestMethod.GET)
    public BaseResponse<List<String>> getAllPinyinList(@RequestParam String character) {
        // 检查输入是否为单个字符
        if (character == null || character.length() != 1) {
            return new BaseResponse<>(400,null, "输入必须是一个单个字符");
        }

        // 获取第一个字符
        char c = character.charAt(0);

        // 调用 PinyinHelper.toPinyinList() 方法
        List<String> pinyinList = PinyinHelper.toPinyinList(c);

        // 返回结果
        return new BaseResponse<>(200,pinyinList, "成功");

    }


    @RequestMapping(value = "/paragraph", method = RequestMethod.POST)
    public BaseResponse<String> updateParagraphPinyin(@RequestBody ChangeWordRequest changeWordRequest) {
        if (changeWordRequest == null) {
            return new BaseResponse<>(400, null, "请求参数为空");
        }

        return wordService.updatePinyin(changeWordRequest);


    }




}
